﻿#-------------------------------------------------------------------------------
# Name:        InformationCollector
# Purpose:
#
# Author:      evob0413
#
# Created:     11.07.2014
# Copyright:   (c) evob0413 2014
# Licence:     <your licence>
#-------------------------------------------------------------------------------
from PIL import Image
from datetime import datetime
from InformationGatheringConstants import *
from ScreenGrabber import ScreenGrabber
from ElementsFinder import ElementsFinder
from ImageRecognizer import ImageRecognizer

# 1. снять скриншот
# 2. получить элементы
# 3. распознать текст
# 4. смапить параметры
# 5. вернуть результат

class InformationCollector(object):

    def getInformation(self):
        now = datetime.now()
        screen_grabber = ScreenGrabber()
        screen_grabber.grab_image()
        #print "Screen grabbed: %s:%s:%s.%s" % (format_timedelta(now))

        finder = ElementsFinder()
        recognizer = ImageRecognizer()

        #now = datetime.now()
        im = finder.findElement(TEST_LEFT, TEST_UPPER, TEST_RIGHT, TEST_BOTTOM)
        #print "Elements found: %s:%s:%s.%s" % (format_timedelta(now))

        #now = datetime.now()
        res = recognizer.recognize_text("mock_key", im)
        print res
        print "Images recogized: %s:%s:%s.%s" % (format_timedelta(now))




def format_timedelta(past):
    delta = datetime.now() - past
    days, seconds, mcseconds = delta.days, delta.seconds, delta.microseconds
    hours = days * 24 + seconds
    minutes = (seconds % 3600)
    seconds = (seconds % 60)
    return str(hours), str(minutes), str(seconds), str(mcseconds)[:3]

def main():
    collector = InformationCollector()
    collector.getInformation()

if __name__ == '__main__':
    main()
